﻿using System;
using System.Xml;
using System.Collections.Generic;

namespace BfLib.Web.RSSLite
{
    public class RSSLiteItem
    {
        private string _title, _link, _description;

        public RSSLiteItem(XmlNode node)
        {
            XmlNode n;

            n = node.SelectSingleNode("title");
            if (n == null)
                throw new Exception("<item> element does not contain the mandatory <title> element");
            else
            {
                if (n.FirstChild == null)
                {
                    this._title = n.Value;
                }
                else
                {
                    this._title = n.ChildNodes[0].Value;
                }
            }

            n = node.SelectSingleNode("link");
            if (n == null)
                throw new Exception("<item> element does not contain the mandatory <link> element");
            else
            {
                if (n.FirstChild == null)
                {
                    this._link = n.Value;
                }
                else
                {
                    this._link = n.ChildNodes[0].Value;
                }
            }

            n = node.SelectSingleNode("description");
            if (n == null)
                throw new Exception("<item> element does not contain the mandatory <description> element");
            else
            {
                if (n.FirstChild == null)
                {
                    this._description = n.Value;
                }
                else
                {
                    this._description = n.ChildNodes[0].Value;
                }
            }

        }

        #region Public accessors

        public string Title
        {
            get { return _title; }
        }

        public string Link
        {
            get { return _link; }
        }

        public string Description
        {
            get { return _description; }
        }

        #endregion
    }

}
